package ch.doublet.jw.pubdownloader;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class PathConfiguration {

	private static final String PATH = "ch.doublet.jw.pubd.path";
	private static final String STANDARDPATH = PATH + ".standard";

	private String tempPath = "";
	private String path = "";
	private String standardPath = "";

	public String getTempPath() {
		if (null == tempPath || tempPath == "") {
			return standardPath;
		}
		return tempPath;
	}

	public void setTempPath(String tempPath) {
		this.tempPath = tempPath;
		this.path = tempPath;
	}

	public PathConfiguration() {

		Properties prop = new Properties();

		try {
			// load a properties file
			prop.load(new FileInputStream("pubd.properties"));

			// get the property value and print it out
			standardPath = prop.getProperty(STANDARDPATH);
			path = prop.getProperty(PATH);

		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public void savePath() {
		Properties prop = new Properties();

		try {

			// save properties to project root folder
			prop.store(new FileOutputStream("config.properties"), null);

		} catch (IOException ex) {
			ex.printStackTrace();
		}

	}

}
